package com.yjh.server.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yjh.pojo.entity.ReservationMain;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Mapper
public interface ReservationMainMapper extends BaseMapper<ReservationMain> {
    @Select("SELECT " +
            "    rtr.reserve_id, " +
            "    MAX(rt.end_hour) AS max_end_hour ," +  // 注意这里加了空格
            "    rm.reserve_date AS reserveDate " +
            "FROM " +  // 单独成行，避免拼接问题
            "    reservation_main rm " +
            "INNER JOIN reserve_time_relation rtr " +
            "    ON rtr.reserve_id = rm.reserve_id " +
            "INNER JOIN reservation_time rt " +
            "    ON rt.time_id = rtr.time_id " +
            "WHERE " +
            "    rm.reserve_status = 0 " +  // 单个=，而非==
            "GROUP BY " +
            "    rtr.reserve_id, rm.reserve_date")
    List<Map<String, Object>> selectOverdueReserves();


    @Select("SELECT " +
            "    MIN(rt.start_hour) AS min_start_hour, " +
            "    MAX(rt.end_hour) AS max_end_hour " +
            "FROM " +
            "    reservation_main rm " +
            "INNER JOIN reserve_time_relation rtr " +
            "    ON rtr.reserve_id = rm.reserve_id " +
            "INNER JOIN reservation_time rt " +
            "    ON rt.time_id = rtr.time_id " +
            "WHERE " +
            "    rtr.reserve_id = #{reserveId}")  // 确保使用 #{} 语法
    Map<String, Object> selectMinMaxTimeByReserveId(@Param("reserveId") Integer reserveId);
}

